package com.bubblegumproject.ogo.remote.tunnel;

import com.bubblegumproject.ogo.remote.io.ActionPacket;

import java.io.Serializable;

/**
 * Response received from the Tunnel endpoint.
 *
 * TODO: This class should include some basic information about the reactor that generated the response
 *
 * @author Azubuko Obele (buko.obele@gmail.com)
 */
public class TunnelResponse implements Serializable {

    private ActionPacket outputPacket;

    private Throwable reactorError;

    private boolean isReactorException;

    public TunnelResponse(ActionPacket packet) {
        assert(packet != null);
        this.outputPacket = packet;
    }

    public TunnelResponse(Throwable error) {
        assert(error != null);
        this.reactorError = error;
        this.isReactorException = true;
    }

    public ActionPacket getOutputPacket() {
        return outputPacket;
    }

    /**
     * @return Exception that the remote {@code Reactor} threw when it reacted to the input
     */
    public Throwable getRemoteReactorError() {
        return reactorError;
    }

    public boolean remoteErrorOccurred() {
        return isReactorException;
    }
}
